package com.restfinder.rate.service;

import java.io.Serializable;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.restfinder.rate.dao.DatabaseRateRepository;
import com.restfinder.rate.dao.RateRepository;
import com.restfinder.rate.model.Rate;
import com.restfinder.restaurant.model.Restaurant;
import com.restfinder.user.model.User;

@Service
@Transactional(rollbackFor=Exception.class)
public class RateService implements Serializable{

	private static final long serialVersionUID = 1L;
	
	@Autowired
	private RateRepository rateIRepository;
	
	public Rate getByUserAndRestaurant(User user, Restaurant restaurant){
		return rateIRepository.getByUserAndRestaurant(user, restaurant);
	}

	public void saveOrUpdate(Rate rate) {
		this.rateIRepository.saveOrUpdate(rate);
	}

	public double getAverage(Restaurant restaurant) {
		return rateIRepository.getAverage(restaurant);
	}
}
